package com.joshondesign.sdljava.demo;

import com.joshondesign.sdljava.SDLUtil;
import com.joshondesign.sdljava.SDL_Surface;
import com.joshondesign.sdljava.gfx.*;

import java.io.File;

/**
 * Created by IntelliJ IDEA.
 * User: josh
 * Date: 9/11/11
 * Time: 4:11 PM
 * To change this template use File | Settings | File Templates.
 */
public class PaintFillTest implements SDLUtil.InitCallback {
    public static void main(String ... args) {
        SDLUtil.init(new PaintFillTest());
    }

    public void callback() throws Exception {
        //define linear gradient with stops and wither it's vertical or horiz
        Util.standard_init();
        SDL_Surface surface = null;
        if("arm".equals(System.getProperty("os.arch"))) {
            surface = Util.createFullscreenWindow();
        } else {
            surface = Util.createResizableWindow(1000, 600);
        }
        final Scene scene = new Scene(surface);
        scene.setBackgroundFill(SColor.BLACK);
        Layer layer = new Layer(surface.getFormat());
        scene.add(layer);

        final LinearGradient gradient = new VerticalLinearGradient(0,50)
                .addColor(0.0,SColor.BLUE)
                .addColor(0.3,SColor.WHITE)
                .addColor(0.7, SColor.RED)
                .addColor(1.0, SColor.WHITE);

        final LinearGradient gradient2 = new HorizontalLinearGradient(0,50)
                .addColor(0.0,SColor.BLUE)
                .addColor(0.3,SColor.WHITE)
                .addColor(0.7,SColor.RED)
                .addColor(1.0,SColor.WHITE);
        final SPattern pattern = new SPattern(new File("src/resources/checkerboard.png"));

        layer.add(new Node() {
            @Override
            public void draw(GFX gfx) {
                gfx.setPaint(SColor.RED);
                doDrawing(gfx);

                gfx.translate(250,0);
                gfx.setPaint(gradient);
                doDrawing(gfx);

                gfx.setPaint(gradient2);
                gfx.translate(250, 0);
                doDrawing(gfx);

                gfx.setPaint(pattern);
                gfx.translate(250,0);
                doDrawing(gfx);


                gfx.translate(-250*3,0);
            }
        });

        scene.setTargetFPS(5);
        scene.start();
    }

    private void doDrawing(GFX gfx) {
        gfx.drawLine(       0,  0,      200,    40);
        gfx.drawRect(       0,  50,     200,    40);
        gfx.fillRect(       0,  100,    200,    40);
        gfx.drawRoundRect(  0,  150,    200,    40,     10);
        gfx.fillRoundRect(  0,  200,    200,    40,     10);
        gfx.drawEllipse(    0,  250,    200,    40);
        gfx.fillEllipse(    0,  300,    200,    40);
    }
}
